/**
 * Класс таблицы списка.
 * @lends phonebook.view.AddNewDialog
 */
phonebook.view.AddNewDialog = Base.extend({
	
    controller : null,		// объект управления процессами Приложения      
    orgUnitType: null,
    orgUnit:null,
    post:null,
    person: null,
    phoneType: null,
    phone: null,
    room: null,
    orgUnitPost:null,
    /**
     * Конструктор класса
     * @author Konstantin Chumachenko
     * 
     * @augments Base
     * @class Класс панели списка пользователей.
     * 
     * <p><b>Пример:</b></p>
     * <pre class="code">
     * var AddNewDialog = new phonebook.view.AddNewDialog(controller);
     * </pre>
     * 
     * @constructs
     * @param {Controller} controller Контроллер приложения.
     */
    constructor : function(controller) {	
        console.log("-- AddNewDialog: Конструктор.");
        this.controller = controller;
        this.domElement = $(SIDEBAR_HOLDER);
        this.render(this.domElement);
    },
	
    /**
     * Возвращает DOM-элемент этой панели 
     * @function
     * @public 
     * @memberOf phonebook.view.AddNewDialog#
     */
    getDomElement : function() {
        return this.domElement;
    },
	
    /**
     * Выполняется отрисовка панели.
     * @private 
     * @function
     * @param (elementDOM) renderTo Элемент DOM, внутри которого будет создан контейнер.
     * @return none
     */
    render : function(renderTo) {
        console.log("-- AddNewDialog: render.");
        var me = this;
        /*
         * orgUniTypeName
         */
        var orgUnitTypeName = new widget.Text({
            id: 'name',
            cls: "inp",
            input : {
                cls : 'inp',
                align: "left",
                width : 130
            },
            label:{
                width : 130,
                align: "right",
                text: 'Name:'
            }
        });
        /*
         * OrgUnitTypeId
         */
        var orgUnitTypeId = new widget.Text({
            id: 'unitTypeId',
            cls: "inp",
            input : {
                cls : 'inp',
                align: "left",
                width : 130
            },
            label:{
                width : 130,
                align: "right",
                text: 'OrgUnitType id:'
            }
        });
        /*
         * perentUnitId
         */
        var orgUnitId = new widget.Text({
            id: 'perentUnitId',
            cls: "inp",
            input : {
                cls : 'inp',
                align: "left",
                width : 130
            },
            label:{
                width : 130,
                align: "right",
                text: 'PerentUnit id:'
            }
        });
        /*
         * perentUnitId
         */
        var orgUnitPostId = new widget.Text({
            id: 'orgUnitPostId',
            cls: "inp",
            input : {
                cls : 'inp',
                align: "left",
                width : 130
            },
            label:{
                width : 130,
                align: "right",
                text: 'UnitPost id:'
            }
        });
        /*
         * phoneType
         */
        var phoneType = new widget.Text({
            id: 'phoneType',
            cls: "inp",
            input : {
                cls : 'inp',
                align: "left",
                width : 130
            },
            label:{
                width : 130,
                align: "right",
                text: 'phoneType id:'
            }
        });
        /*
         * phoneNumber
         */
        var phoneNumber = new widget.Text({
            id: 'phoneNumber',
            cls: "inp",
            input : {
                cls : 'inp',
                align: "left",
                width : 130
            },
            label:{
                width : 130,
                align: "right",
                text: 'phoneNumber:'
            }
        });
        /*
         * roomName
         */
        var roomName = new widget.Text({
            id: 'roomName',
            cls: "inp",
            input : {
                cls : 'inp',
                align: "left",
                width : 130
            },
            label:{
                width : 130,
                align: "right",
                text: 'room name:'
            }
        });
        /*
         * Name
         */
        var name = new widget.Text({
            id: 'name',
            cls: "inp",
            input : {
                cls : 'inp',
                align: "left",
                width : 130
            },
            label:{
                width : 130,
                align: "right",
                text: 'Name:'
            }
        });
        /*
         * surname
         */
        var surname = new widget.Text({
            id: 'surname',
            cls: "inp",
            input : {
                cls : 'inp',
                align: "left",
                width : 130
            },
            label:{
                width : 130,
                align: "right",
                text: 'Surname:'
            }
        });
        /*
         * surname
         */
        var patronymic = new widget.Text({
            id: 'patronymic',
            cls: "inp",
            input : {
                cls : 'inp',
                align: "right",
                width : 130
            },
            label:{
                width : 130,
                align: "right",
                text: 'Patronymic:'
            }
        });
        /*
         * Person ID
         */
        var personId = new widget.Text({
            id: 'personId',
            cls: "inp",
            input : {
                cls : 'inp',
                align: "left",
                width : 130
            },
            label:{
                width : 130,
                align: "right",
                text: 'Person ID:'
            }
        });
        /*
         * Room ID
         */
        var roomId = new widget.Text({
            id: 'roomId',
            cls: "inp",
            input : {
                cls : 'inp',
                align: "left",
                width : 130
            },
            label:{
                width : 130,
                align: "right",
                text: 'Room ID:'
            }
        });
        /*
         * Post ID
         */
        var postId = new widget.Text({
            id: 'postId',
            cls: "inp",
            input : {
                cls : 'inp',
                align: "left",
                width : 130
            },
            label:{
                width : 130,
                align: "right",
                text: 'Post ID:'
            }
        });
        var phoneTypeName = new widget.Text({
            id: 'phoneTypeName',
            cls: "inp",
            input : {
                cls : 'inp',
                align: "left",
                width : 130
            },
            label:{
                width : 130,
                align: "right",
                text: 'Phone Type Name:'
            }
        });
        /*
         * OrgUnitType dialog
         */
        me.orgUnitType = new widget.Dialog({
            title : 'Add orgUnitPost',
            modal : true,
            height: 200,
            width : 400,
            cls : 'content',
            items :  [orgUnitTypeName,"<div id='orgUnitPostError'></div>"],
            buttons: [
            {
                text: "Добавить",
                click: function() {
                    var data={
                        name:orgUnitTypeName.value
                    };
                    me.controller.addOrgUnitType(data);
                }
            },
            {
                text: "Отмена",
                click: function() {
                    me.orgUnitType.close();
                }
            }
            ]
        });
        /*
         * orgUnit dialog
         */
        me.orgUnit = new widget.Dialog({
            title : 'Add orgUnit',
            modal : true,
            height: 300,
            width : 400,
            cls : 'content',
            items :  [orgUnitTypeName,orgUnitTypeId,orgUnitId,"<div id='orgUnitError'></div>"],
            buttons: [
            {
                text: "Добавить",
                click: function() {
                    var data={
                        name:orgUnitTypeName.value,
                        unitType: orgUnitTypeId.value,
                        perent:orgUnitId.value
                    };
                    me.controller.addOrgUnit(data);
                }
            },
            {
                text: "Отмена",
                click: function() {
                    me.orgUnit.close();
                }
            }
            ]
        });
        /*
         * post dialog
         */
        me.post = new widget.Dialog({
            title : 'Add Post',
            modal : true,
            height: 300,
            width : 300,
            cls : 'content',
            items :  [orgUnitTypeName,"<div id='postError'></div>"],
            buttons: [
            {
                text: "Добавить",
                click: function() {
                    var data={
                        name:orgUnitTypeName.value        
                    };
                    me.controller.addPost(data);
                }
            },
            {
                text: "Отмена",
                click: function() {
                    me.post.close();
                }
            }
            ]
        });
        /*
         * phoneType dialog
         */
        me.phoneType = new widget.Dialog({
            title : 'Add phone type',
            modal : true,
            height: 300,
            width : 350,
            cls : 'content',
            items :  [phoneTypeName,"<div id='phoneTypeError'></div>"],
            buttons: [
            {
                text: "Добавить",
                click: function() {
                    var data={
                        name:phoneTypeName.value                     
                    };
                    me.controller.addPhoneType(data);
                }
            },
            {
                text: "Отмена",
                click: function() {
                    me.phoneType.close();
                }
            }
            ]
        });
        /*
         * phone dialog
         */
        me.phone = new widget.Dialog({
            title : 'Add phone',
            modal : true,
            height: 300,
            width : 350,
            cls : 'content',
            items :  [phoneNumber,orgUnitPostId,phoneType,"<div id='phoneError'></div>"],
            buttons: [
            {
                text: "Добавить",
                click: function() {
                    var data={
                        number:phoneNumber.value,
                        unitPost:orgUnitPostId.value,
                        type:phoneType.value
                    };
                    me.controller.addPhone(data);
                }
            },
            {
                text: "Отмена",
                click: function() {
                    me.phone.close();
                }
            }
            ]
        });
        /*
         * room dialog
         */
        me.room = new widget.Dialog({
            title : 'Add room',
            modal : true,
            height: 300,
            width : 350,
            cls : 'content',
            items :  [roomName,"<div id='roomError'></div>"],
            buttons: [
            {
                text: "Добавить",
                click: function() {
                    var data={
                        name:roomName.value
                    };
                    me.controller.addRoom(data);
                }
            },
            {
                text: "Отмена",
                click: function() {
                    me.room.close();
                }
            }
            ]
        });
        /*
         * person dialog
         */
        me.person = new widget.Dialog({
            title : 'Add person',
            modal : true,
            height: 300,
            width : 350,
            cls : 'content',
            items :  [name,surname,patronymic,"<div id='personError'></div>"],
            buttons: [
            {
                text: "Добавить",
                click: function() {
                    var data={
                        name:name.value,
                        surname: surname.value,
                        patronymic: patronymic.value
                    };
                    me.controller.addPerson(data);
                }
            },
            {
                text: "Отмена",
                click: function() {
                    me.person.close();
                }
            }
            ]
        });
        /*
         * orgUnitPost dialog
         */
        me.orgUnitPost = new widget.Dialog({
            title : 'Add orgUnitPost',
            modal : true,
            height: 300,
            width : 350,
            cls : 'content',
            items :  [orgUnitId,personId,roomId,postId,"<div id='orgUnitPostError'></div>"],
            buttons: [
            {
                text: "Добавить",
                click: function() {
                    var data={
                        orgUnitId:orgUnitId.value,
                        personId: personId.value,
                        roomId: roomId.value,
                        postId: postId.value
                    };
                    me.controller.addOrgUnitPost(data);
                }
            },
            {
                text: "Отмена",
                click: function() {
                    me.orgUnitPost.close();
                }
            }
            ]
        });
    }
});